/**
 * 时间：2024-08-25
 * 作者：waygc
 * 描述：详情页主文件，提供在点击后展开详情内容的功能
 * 
 */
import React from "react";
import dataApi from "./data";
import { Button } from "antd";

import "./detail.css";
import { withRouter } from "./../../lib/utils";
import { contentBorderStyle } from "../../lib/custom-styles";

class DataDetail extends React.Component {
	constructor (props) {
		super(props);
		this.rowId = props.router.params.id;
		this.getDatas();
	}

	state = {
		detail: {}
	};

	getDatas = async () => {
		const res = await dataApi.getDetail(this.rowId);
		if (res.success) {
			this.setState({ detail: res.data });
		} else {
			// 获取失败
		}
	}

	handleBtnClickBack = () => {
		this.props.router.navigate(-1);
	}

	render () {
		return (
			<div style={contentBorderStyle}>
				<div class="data-detail-box">
					<div class="h3">{ this.state.detail.name }</div>
					<div>
						<Button size="small" type="primary" onClick={this.handleBtnClickBack}>返回列表</Button>
					</div>
				</div>
				<pre style={contentBorderStyle}>{ JSON.stringify(this.state.detail, null, "	") }</pre>
			</div>
		);
	}
}

export default withRouter(DataDetail);
